const systemInfo = uni.getSystemInfoSync();

const SERVER_URL = {
  development: {
    // #ifdef H5
    ...{
      URL_REMOTE: location.origin,
      URL_ASSETS: location.origin
    },
    // #endif
    // #ifndef H5
    ...{
      URL_REMOTE: process.env.DEV_URL,
      URL_ASSETS: process.env.DEV_URL,
    },
    // #endif
    URL_WEBSOCKET: null,
    DEBUG_MODE: true,

    PUBLIC_KEY: "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDfYYttzWj8YWdtTcf4SSuFfCLkwP2GSqiRoDfC0g1g17oPQZIPmvPtMqT0cA6XOP2zXkmHibVnBcC5fSWX9TYnAXpBVggslTiyL2+GH749cMcNhRoKSLOmu/moCqtwIs/T5BfQqVAE+mISwvtcEQ2/V82eKwaVfox88d6tuN1T8QIDAQAB",
    APP_KEY: "5f231699ac8f7eef5d3b3c6b9e62e902",
  },
  production: {
    PUBLIC_KEY: "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDfYYttzWj8YWdtTcf4SSuFfCLkwP2GSqiRoDfC0g1g17oPQZIPmvPtMqT0cA6XOP2zXkmHibVnBcC5fSWX9TYnAXpBVggslTiyL2+GH749cMcNhRoKSLOmu/moCqtwIs/T5BfQqVAE+mISwvtcEQ2/V82eKwaVfox88d6tuN1T8QIDAQAB",
    APP_KEY: "5f231699ac8f7eef5d3b3c6b9e62e902",

    URL_WEBSOCKET: null,
    DEBUG_MODE: false,
    // #ifdef H5
    ...{
      URL_REMOTE: location.origin,
      URL_ASSETS: location.origin
    },
    // #endif
    // #ifndef H5
    ...{
      URL_REMOTE: process.env.RELEASE_URL,
      URL_ASSETS: process.env.RELEASE_URL,
    },
    // #endif
  },
}

const config = {
  APP_VERSION_CODE: Number(systemInfo.appWgtVersion?.replace(/[^0-9]/ig, '')) || systemInfo.appVersionCode,
  APP_VERSION: systemInfo.appWgtVersion || systemInfo.appVersion,
  APP_NAME: systemInfo.appName,
  OS_VERSION: +systemInfo.osVersion.split(".")[0],
  OS_NAME: systemInfo.osName,
  PLATFORM: systemInfo.uniPlatform,
  DEVICE_BRAND: systemInfo.deviceBrand,
  DEVICE_MODEL: systemInfo.deviceModel,
  DEVICE_ID: systemInfo.deviceId,
  STATUS_BAR_HEIGHT: systemInfo.statusBarHeight || 0,

  ...(SERVER_URL[process.env.NODE_ENV as keyof typeof SERVER_URL]),
  ROUTE_PREFIX: process.env.ROUTE_PREFIX,
  API_PREFIX: "/api",

  CONFIG_GET: "static/config.json",
  APP_UPDATE: "/appVersion",

  API_USER_INFO_GET: "/userInfo",
  API_USER_INFO_SET: "/perfectUserInfo",
  API_FILE_UPLOAD: "/uploadImage",
  API_CONFIG_GET: null,

  URL_REMOTE_ASSETS: "https://image.qiqi-life.cn",

  PACKAGE_NAME: "com.uni.app",

  PAGE_LOGIN_APPLETS: null,
  PAGE_HOME_CLIENT: "/pages/client/tabs/home",
  PAGE_LOGIN_ACCOUNT: "/pages/client/auth/login",
  PAGE_NOT_FOUND: "/pages/common/error",
  PAGE_UPGRADE: "/pages/common/upgrade",

  PATH_STATIC: "/static/server",
  STORAGE_KEY_USER_INFO: "userInfo",
  STORAGE_USER_INFO_EXPIRE_TIME: 7,
  FIELD_TOKEN: "token",

  COLOR_TRANSPARENT: "transparent",
  COLOR_BLACK: "#000",
  COLOR_WHITE: "#fff",
  COLOR_TEXT: "#333",
  COLOR_DISABLED: "#eee",
  COLOR_SUBTITLE: "#666",
  COLOR_SECTION: "#21202e",
  COLOR_PRIMARY: "#5c33c9",
  COLOR_GREY: "#888",
  COLOR_PLACEHOLDER: "#999",
  COLOR_TEXT_INVERSE: "#0c003b",
  COLOR_BACKGROUND: "#0b0126",
  COLOR_LABEL: "#c0b0df",
  COLOR_STRESS: "#8777e1",
};

let URL_STATIC = config.PATH_STATIC;
// #ifdef MP
URL_STATIC = config.URL_ASSETS + URL_STATIC;
// #endif

export default Object.assign(config,
  { URL_STATIC },
  uni.getStorageSync("$config") || {},
  uni.getStorageSync("$debug")
);